package com.example.dangerouscargodriver.widget;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.dangerouscargodriver.R;
import com.example.dangerouscargodriver.entry.HandleRecordInfo;
import com.example.dangerouscargodriver.entry.ResourceInfo;
import com.example.dangerouscargodriver.ui.activity.ResourceDetailActivity;

public class HandleRecordInfoView extends LinearLayout{

    private static final String TAG = "HandleRecordInfoView";
    private Context mContext = null;
    private HandleRecordInfo mRecordInfo = null;
    private ImageView mRecordIcon = null;
    private TextView mRecordName = null;
    private TextView mRecordTime = null;
    private TextView mRecordDesc = null;

    public HandleRecordInfoView(Context context, HandleRecordInfo info) {
        this(context, null, info);
    }

    public HandleRecordInfoView(Context context, AttributeSet attrs, HandleRecordInfo info) {
        this(context, attrs, 0, info);
    }

    public HandleRecordInfoView(Context context, AttributeSet attrs, int defStyleAttr, HandleRecordInfo info) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, info);
    }

    public void init(Context context, AttributeSet attrs, HandleRecordInfo info) {
        mContext = context;
        mRecordInfo = info;
        View itemLayout = LayoutInflater.from(context).inflate(R.layout.layout_handle_record_info_item, this);
        mRecordIcon = itemLayout.findViewById(R.id.tv_record_icon);
        mRecordName = itemLayout.findViewById(R.id.tv_record_name);
        mRecordTime = itemLayout.findViewById(R.id.tv_record_time);
        mRecordDesc = itemLayout.findViewById(R.id.tv_record_desc);

        //执行绑定数据的操作
        Glide.with(this).load(mRecordInfo.getIcon()).into(mRecordIcon);
        mRecordName.setText(mRecordInfo.getName());
        mRecordTime.setText(mRecordInfo.getTime());
        mRecordDesc.setText(mRecordInfo.getDesc());
    }

    public void bindData(HandleRecordInfo info){
        if(info != null){
            mRecordIcon.setImageURI(Uri.parse(mRecordInfo.getIcon()));
            mRecordName.setText(mRecordInfo.getName());
            mRecordTime.setText(mRecordInfo.getTime());
            mRecordDesc.setText(mRecordInfo.getDesc());
        }
    }
}
